angular.module('start.guide.guidedetail.ctrl', [])

  .controller('guidedetailCtrl', function($scope,$ionicSlideBoxDelegate, $ionicSlideBoxDelegate, $rootScope, $$UserOrderService, $stateParams, $location, $ionicLoading, $$GuideService) {
    console.log("guidedetailCtrl");

    $scope.guideId = $stateParams.guideId;
    if ($stateParams.guideId == "" || $stateParams.guideId == null) {
      $location.path();
    }

    // 评论列表
    // {userName: "2", headPic: "2.pg", grade: 5, comment: "1", evaluateTime: "2018-01-03 11:41:50.0"}
    $scope.evaluateList = [];
    $scope.guideVO = {
      grade: null,
      guideId: "",
      headPic: "",
      lifePic: "",
      serviceCity: "",
      servicePrice: null,
      serviceRoute: "",
      type: 1,
      userName: "",

      shopping: 0,
      travel: null,
      business: 0,
      food: 0,
    };
    $scope.hotGuideList = [];
    $scope.userInfoVO = {};
    $scope.isAttentioned = 0;

    $scope.guideVO_serviceRouteArrary = [];

    $scope.lifePicsData = [];
    $scope.lifePicsDatagallery = [];
    // $scope.lifePicsData = [{ src: 1 }, { src: 22 }, { src: 333 }];
    // 轮播图数据

    // 获取向导详情
    $$GuideService.getGuideDetail($scope.guideId)
      .then(function(res) {
        if (res.data == undefined) {
          $ionicLoading.show({
              template: "信息不存在",
              noBackdrop: true,
              duration: 1500
            });
          $rootScope.$ionicGoBack();
          return;
        }
        $scope.guideVO = res.data.guideInfoVO;
        $scope.hotGuideList = res.data.hotGuideList;
        $scope.evaluateList = res.data.evaluateList;
        $scope.isAttentioned = res.data.isAttentioned || 0;
        $scope.userInfoVO = res.data.userInfoVO;
        var array = [];
        for (var i in res.data.guideInfoVO.lifePic.split(",")) {
          $scope.lifePicsData.push({ src: res.data.guideInfoVO.lifePic.split(",")[i] });
          array.push({ src: res.data.guideInfoVO.lifePic.split(",")[i] });
        }
        console.info(array);
        // angular.extend($scope.lifePicsDatagallery, $scope.lifePicsData);
        $scope.lifePicsDatagallery = array;
        // $scope.lifePicsDatagallery = $scope.lifePicsData;
        $scope.guideVO_serviceRouteArrary = res.data.guideInfoVO.serviceRoute.split("#");
        $scope.guideorder = guideorder;
        $ionicSlideBoxDelegate.update();

      });

    // 通过导游id获取导游评价
    $$GuideService.getGuideEveluatelist($scope.guideId, 1, 2)
      .then(function(res) {
        if (res.data == null || res.data == undefined) {} else {
          $scope.evaluateList = res.data;
        }
      });


    var guideorder = function() {
      $location.path("guideorder/" + $scope.guideId);
    };

    $scope.attentionGuide = function() {
      if ($rootScope.isLogined()) {
        if ($scope.isAttentioned === 0) {
          $$GuideService.attention($scope.guideId).then(function(res) {
            $ionicLoading.show({
              template: res.msg,
              noBackdrop: true,
              duration: 1500
            });
            $scope.isAttentioned = 1;
          });
        } else if ($scope.isAttentioned === 1) {
          $$GuideService.cancelAttention($scope.guideId).then(function(res) {
            $ionicLoading.show({
              template: res.msg,
              noBackdrop: true,
              duration: 1500
            });
            $scope.isAttentioned = 0;
          });
        }
      } else {
        $ionicLoading.show({
          template: "请登录",
          noBackdrop: true,
          duration: 1500
        });
        $location.path("login");
      }
    };


    $scope.moreguideevaluate = function() {
      $location.path("guideevaluatelist/" + $scope.guideId);
    };


  });
